package com.liury.bbs.mapper;

import com.liury.bbs.entity.User;
import lombok.Data;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserMapper {
    @Select("select count(*) from user")
    public int countuser();


    //验证用户
    @Select("select * from user where name=#{name}")
    public User checkName(String name);

//注册
    @Insert("insert into user (name,password,email,sex,regedit_time) values(#{name},#{password},#{email},#{sex},#{regedit_time})")
    public void insert(User user);


    //登录
    @Select("select * from user where name=#{name} and password=#{password}")
    public User login(String name,String password);

    @Select("select * from user where id=#{id}")
    public User getById(int id);


    //用户查询
    @Select("<script>"+
            "select * from user where 1=1\n"+
            "       <if test=\"name!=null and name !=''\">\n  "+
            "          and name like concat('%',#{name},'%')\n"+
            "</if>\n"+
            "</script>")
    public List<User> getUsers(String name);

    @Delete("delete from user where id=#{id}")
    public void delete(Integer id);

    @Update("update user set name=#{name},password=#{password},email=#{email},sex=#{sex} where id=#{id}")
    public void update(User user);

    @Select("select * from user")
    public List<User> findAll();
}


